package com.zhouheng.springbootredis.module.girl.controller;

import com.zhouheng.springbootredis.common.entity.Girl;
import com.zhouheng.springbootredis.common.entity.GirlInsertVo;
import com.zhouheng.springbootredis.common.exception.BaseException;
import com.zhouheng.springbootredis.module.girl.service.GirlService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * girl控制层
 *
 * @author 周恒
 * @date 20190226 16:31:21
 * @since v1.0
 */
@Api(tags = "Girl测试Redis")
@RestController
@RequestMapping("/girl")
public class GirlController {

    @Autowired
    private GirlService girlService;

    @ApiOperation("根据ID查询Girl")
    @GetMapping(value = "/findOne")
    public Girl findOne(Integer id){
        if(null == id){
            throw new BaseException("参数异常");
        }
        return girlService.findOne(id);
    }

    @ApiOperation("根据ID修改Girl")
    @PostMapping(value = "/updateGirl")
    public void updateGirl(@RequestBody Girl girl){
        if(null == girl || null == girl.getId()
                || (null == girl.getAge() && null == girl.getName())){
            throw new BaseException("参数异常");
        }
        girlService.updateGirl(girl);
    }

    @ApiOperation("插入一条Girl")
    @PostMapping(value = "insertGirl")
    public void insertGirl(@RequestBody GirlInsertVo girl){
        if(null == girl
                || null == girl.getAge()
                || null == girl.getName()){
            throw new BaseException("参数异常");
        }
        girlService.insert(girl);
    }

    @ApiOperation("根据ID删除Girl")
    @PostMapping(value = "deleteById")
    public void deleteById(Integer id){
        if(null == id){
            throw new BaseException("参数异常");
        }
        girlService.deleteById(id);
    }

}
